
//5468. 第 k 个缺失的正整数
/**
 * @param {number[]} arr
 * @param {number} k
 * @return {number}
 */
var findKthPositive = function(arr, k) {
    let loss = 0
    let num =1
    for (const n of arr) {
        while(num<n){
            loss++
            if(loss===k) return num
            num++
        }
        num++
    }
    return num+(k-loss)-1
};


//5469. K 次操作转变字符串
/**
 * @param {string} s
 * @param {string} t
 * @param {number} k
 * @return {boolean}
 */

 //five解法
// var canConvertString = function(s, t, k) {
//     if(s.length!==t.length) return false
//     let needs = new Map()
//     for(let i=0;i<s.length;i++){
//         let need = (t.charCodeAt(i)+26-s.charCodeAt(i))%26
//         if(need!=0) {
//             let times = needs.has(need)?needs.get(need):0
//             needs.set(need,times+1)
//         }   
//     }
//         for(let i=1;i<=k&&needs.length!=0;i++){
//             let need = i%26
//             if(needs.has(need)){
//                 let times = needs.get(need)
//                 if(times===1)needs.delete(need)
//                 else needs.set(need,times-1)
//             }
//         }
    
//     return needs.size===0
// };

var canConvertString = function(s, t, k) {
    if(s.length!==t.length) return false
    let needs = new Map()
    let max = -1
    for(let i=0;i<s.length;i++){
        let need = (t.charCodeAt(i)+26-s.charCodeAt(i))%26
        if(need!=0) {
            let times = needs.has(need)?needs.get(need):0
            max = Math.max(max,times*26+need)
            needs.set(need,times+1)
        }   
    }
    return max<=k
};

